/**
 * 
 */
package ar.posti.framework.query.core.filter.criteria;

import java.util.Map;

import ar.posti.framework.query.core.filter.AbstractBooleanCriteria;
import ar.posti.framework.query.core.parameters.ParameterContainer;

/**
 * @author Posti
 */
public abstract class ComparisonCriteria extends AbstractBooleanCriteria {
	private String leftOperand;
	private String rightOperand;
	private ParameterContainer container;

	public ComparisonCriteria(String leftOperand, String rightOperand) {
		this.container = new ParameterContainer();
		this.leftOperand = this.container.declareParameter(leftOperand);
		this.rightOperand = this.container.declareParameter(rightOperand);
	}

	public String getLeftOperand() {
		return this.leftOperand;
	}

	public String getRightOperand() {
		return this.rightOperand;
	}

	public void bindVariable(String parameter, Object value) {
	    if (this.container.isDeclaredVariable(parameter)) {
	    	if (value != null)
	    		this.container.bindVariable(parameter, value);
	    	else
	    		this.container.unbindVariable(parameter);
	    }
	}

	public boolean isActive() {
		return this.container.isInitialized(this.rightOperand);
	}

	public Map<String, Object> getVariables() {
		return this.container.getVariables();
	}

	@Override
	public String toString() {
		return this.toString(this.leftOperand, this.rightOperand);
	}

	public abstract String toString(String leftOperand, String rightOperand);
}
